package com.daffodil.storage.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSClientBuilder;
import com.daffodil.storage.properties.AliyunProperties;
import com.daffodil.storage.properties.StorageProperties;

/**
 * 
 * @author yweijian
 * @date 2022年12月9日
 * @version 2.0.0
 * @description
 */
@Component
@Configuration
@ConditionalOnProperty(name = StorageProperties.NAME, havingValue = StorageProperties.ALIYUN)
public class AliyunClientConfig {

    @Bean
    @ConditionalOnMissingBean
    public OSSClient ossClient(StorageProperties storageProperties) {
        AliyunProperties properties = storageProperties.getAliyun();
        OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(properties.getEndpoint(), properties.getAccessKey(), properties.getSecretKey());
        return ossClient;
    }
}
